package pack.View;

import java.util.ArrayList;
import pack.model.Art;
import pack.model.Model;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;

/**
 * Main view class, handling all the graphics.
 * 
 * @author Qw4z1
 *
 */
public class GameScreen implements Screen{
	/**
	 * @uml.property  name="gameModel"
	 * @uml.associationEnd  multiplicity="(1 1)"
	 */
	Model gameModel;
	/**
	 * @uml.property  name="guiCam"
	 * @uml.associationEnd  multiplicity="(1 1)"
	 */
	OrthographicCamera guiCam;
	/**
	 * @uml.property  name="spriteList"
	 */
	ArrayList<Sprite> spriteList;
	/**
	 * @uml.property  name="spriteBatch"
	 * @uml.associationEnd  multiplicity="(1 1)"
	 */
	SpriteBatch spriteBatch = new SpriteBatch();
	
	public GameScreen(Model model){
		guiCam = new OrthographicCamera(Gdx.graphics.getWidth(),Gdx.graphics.getHeight());
		guiCam.zoom = 0.6f;
		gameModel = model;
	}

	@Override
	public void pause() {
		
	}

	@Override
	public void resume() {
	
	}

	@Override
	public void dispose() {
				
	}

	@Override
	public void hide() {
		
		
	}
	@Override
	public void render(float arg) {
		GL10 gl = Gdx.graphics.getGL10();
        gl.glClearColor(0.7f, 0.7f, 0.7f, 1);
        gl.glClear(GL10.GL_COLOR_BUFFER_BIT);	// clears the screen before starting the draw
        
        guiCam.position.set(gameModel.getPlayerX(),  gameModel.getPlayerY(), 0);//center camera on player
        guiCam.update();
        spriteBatch.setProjectionMatrix(guiCam.combined);
        spriteBatch.begin(); 
        spriteBatch.draw(Art.getMap(), 0f, 0f);  //draws map
        
        
		spriteList = gameModel.getSprites();      // get Sprites from model and then draw them.
		for (Sprite sprite : spriteList)
		{
			sprite.draw(spriteBatch);	
		}
		spriteBatch.end();
	}

	@Override
	public void resize(int arg0, int arg1) {
		
	}

	@Override
	public void show() {
		
	}
}
